
#define __ctrl(valc) _ctrl = _display displayCtrl valc
private ["_display", "_ctrl", "_typepos", "_nobs"];
if (!X_Client) exitWith {};

if (d_beam_target < 0) exitWith{};

if (x_loop_end) exitWith {};

x_loop_end = true;

if (vehicle player != player) then {unassignVehicle player};

disableSerialization;
_display = uiNameSpace GetVariable "X_TELE_DIALOG";
__ctrl(100102);
_ctrl ctrlEnable false;
__ctrl(100107);
_ctrl ctrlEnable false;
__ctrl(100108);
_ctrl ctrlEnable false;
__ctrl(100109);
_ctrl ctrlEnable false;
__ctrl(100112);
_ctrl ctrlShow true;

d_last_telepoint = d_beam_target;
_global_pos = [];
_global_dir = 180;
_typepos = 0;
_height = 0;
switch (d_beam_target) do {
	case 0: {
		// We first try the marker which sits in the mission.sqm
		_global_pos = markerPos "base_spawn_1";
		// Second we try the flag object
		If ((_global_pos select 0 == 0) And (_global_pos select 1 == 0)) then { _global_pos = getPos FLAG_BASE};
		// Last we try the standard Respawn_West or Respawn_East or Respawn_Guer
		If ((_global_pos select 0 == 0) And (_global_pos select 1 == 0)) then { _global_pos = markerPos format ["respawn_%1", d_side_player_str]};
	};
	case 1: {
		_global_pos = MRR1 modelToWorld [0,-5,0];
		_global_dir = direction MRR1;
		_typepos = 1;
	};
	case 2: {
		_global_pos = MRR2 modelToWorld [0,-5,0];
		_global_dir = direction MRR2;
		_typepos = 1;
	};
	case 3: {
		_lhd = ["LHD_Teleporter_Landing", FLAG_BASE] call XNetGetJIP;
		_global_pos = _lhd modelToWorld [-2,0,0];
		_global_dir = (direction _lhd) - 180;
		_height = (getPosATL _lhd) select 2;
		_typepos = 1;
	};
};
d_beam_target = -1;
player setVelocity [0,0,0];
if (count _global_pos > 2) then {
	if (_typepos == 1) then {
		player setPosATL [_global_pos select 0, _global_pos select 1, _height];
		player setDir _global_dir;
	} else {
		player setPos _global_pos;
		player setDir _global_dir;
	};
	sleep 2;
	closeDialog 0;

	titletext ["", "BLACK IN"];

	_ObjectTypes = [];
	[_ObjectTypes, d_all_ammoboxes] call XfArrayPushStack;
	[_ObjectTypes, d_check_ammo_load_vecs] call XfArrayPushStack;
	_nobs = nearestObjects [player, _ObjectTypes, 30];
	{player reveal _x} forEach _nobs;
};